#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[5], b[5];
map<int, int> cnt;
int ans;
void solve() {
  // turn on 1
  rep(i, 0, 4) {
    rep(j, 0, 4) b[j] = a[j];
    rep(j, 1, 9) {
      b[i] = (a[i] + j) % 10;
      int res = 0;
      rep(k, 0, 4) res = res * 10 + b[k];
      cnt[res]++;
      if (cnt[res] == n) ans++;
    }
  }
  // turn on 2
  rep(i, 0, 3) {
    rep(j, 0, 4) b[j] = a[j];
    rep(j, 1, 9) {
      b[i] = (a[i] + j) % 10;
      b[i + 1] = (a[i + 1] + j) % 10;
      int res = 0;
      rep(k, 0, 4) res = res * 10 + b[k];
      cnt[res]++;
      if (cnt[res] == n) ans++;
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) {
    rep(j, 0, 4) cin >> a[j];
    solve();
  }
  cout << ans;
  return 0;
}